package com.dc2013.followme;

import com.dc2013.adapter.ViewPagerAdapter;

import android.os.Bundle;
import android.os.Parcelable;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.LayoutParams;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class ImageView_Activity extends Activity
{
	ViewPager mPager;
	RelativeLayout Rl;
	FrameLayout Fl;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		FrameLayout frame = new FrameLayout(this);
		FrameLayout.LayoutParams main= new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		frame.setLayoutParams(main);
		frame.setBackgroundColor(Color.BLACK);
		
		ViewPager mPager = new ViewPager(this);
		FrameLayout.LayoutParams param = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
		mPager.setLayoutParams(param);
		
		RelativeLayout tool = new RelativeLayout(this);
		RelativeLayout.LayoutParams param2 = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		param2.setMargins(20, 0, 20, 20);
		tool.setPadding(20, 0, 20, 20);
		tool.setVisibility(View.VISIBLE);
		tool.setGravity(Gravity.BOTTOM|Gravity.RIGHT);
		tool.setLayoutParams(param2);
		
		
		final ImageView fun = new ImageView(this);
		ImageView share = new ImageView(this);
		ImageView comment = new ImageView(this);
		
		RelativeLayout.LayoutParams img3 = new RelativeLayout.LayoutParams(50,50);
		img3.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
		img3.setMargins(0,0,15,0);
		comment.setId(3);
		comment.setImageResource(R.drawable.icon_comment);
		
		RelativeLayout.LayoutParams img2 = new RelativeLayout.LayoutParams(50,50);
		img2.addRule(RelativeLayout.LEFT_OF, 3);
		img2.setMargins(0,0,15,0);
		share.setId(2);
		share.setImageResource(R.drawable.button_share);
		
		
		RelativeLayout.LayoutParams img = new RelativeLayout.LayoutParams(50,50);
		img.addRule(RelativeLayout.LEFT_OF, 2);
		img.setMargins(0,0,15,0);
		fun.setId(1);
		fun.setImageResource(R.drawable.button_not_fun);
		fun.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				fun.setImageResource(R.drawable.button_fun);
			}
		});
		
		
		
		
		tool.addView(fun,img);
		tool.addView(share, img2);
		tool.addView(comment,img3);
		frame.addView(mPager,param);
		frame.addView(tool,param2);
		setContentView(frame);
		/*Rl = (RelativeLayout)findViewById(R.id.tool);
		Fl = (FrameLayout)findViewById(R.id.view);		
		mPager = (ViewPager) findViewById(R.id.pager);
*/
	    
	 /*   mTouchListener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				Log.d("TAG", "fuckfuck");
				if(Rl.getVisibility()==v.INVISIBLE){
					Rl.setVisibility(View.VISIBLE);				
				}
				else Rl.setVisibility(View.INVISIBLE);	
				}

	   };*/
//		Rl.setOnClickListener(mTouchListener);
		mPager.setAdapter(new PagerAdapterClass(getApplicationContext()));
//		mPager.setPageMargin(getResources().getDisplayMetrics().widthPixels / -9);
	    mPager.setOffscreenPageLimit(5); // 미리 로드할 개수 3개 로드하고싶으면 2

	}
	
	public class PagerAdapterClass extends PagerAdapter{
		LayoutInflater mInflater;
		Context context;

		

		PagerAdapterClass(Context c) {
			super();
			this.context=c;
			mInflater = LayoutInflater.from(c);
		}

		@Override
		public int getCount() {
			return 4;
		}

		@Override
		public boolean isViewFromObject(View pager, Object obj) { // instantiateItem에서
																	// 생성한 객체를 이용할
																	// 것인지 여부를 반환
			return pager == obj;
		}

		/*@Override
		public Object instantiateItem(View pager, int position) { // view를 등록한다.
			View v = null;
			if (position == 0) {
				v = mInflater.inflate(R.layout.inflate_one, null);
			} else if (position == 1) {
				v = mInflater.inflate(R.layout.inflate_two, null);
			} else if (position == 2){
				v = mInflater.inflate(R.layout.inflate_three, null);
			} else 	v = mInflater.inflate(R.layout.inflate_four, null);
			
			

			((ViewPager) pager).addView(v, 0);

			return v;
		}*/
		@Override
		public Object instantiateItem(ViewGroup container, final int position) { // view를 등록한다.
			View v = null;
			
			ImageView img = new ImageView(context);
			img.setImageResource(R.drawable.testpicture);
			
			container.addView(img, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
//			img.setOnClickListener(mTouchListener);

			return img;
		}

		@Override
		public void restoreState(android.os.Parcelable arg0, ClassLoader arg1) {
		}

		@Override
		public Parcelable saveState() {
			return null;
		}

		@Override
		public void startUpdate(View arg0) {
		}

		@Override
		public void finishUpdate(View arg0) {
		}

//		@Override
//		public float getPageWidth(int position) {
//			return 0.9f;
//		} // 스택 구현 시 중요부분, 숫자가 작아질수록 여백이 커진다.
//		
		@Override
		public void destroyItem(View pager, int position, Object view) {	
			((ViewPager)pager).removeView((View)view);
		}

	}


}
